<template>
  <!-- 搜索工作栏 -->
  <ContentWrap>
    <Search :schema="allSchemas.searchSchema" @search="setSearchParams" @reset="setSearchParams">
      <!-- 新增等操作按钮 -->
      <template #actionMore>
        <!-- <el-button
          type="primary"
          plain
          @click="openForm('create')"
          v-hasPermi="['pro:detention-review-center:create']"
        >
          <Icon icon="ep:plus" class="mr-5px" /> 新增
        </el-button> -->
      </template>
    </Search>
  </ContentWrap>

  <!-- 列表 -->
  <ContentWrap>
    <Table
      :columns="allSchemas.tableColumns"
      :data="tableObject.tableList"
      :loading="tableObject.loading"
      :pagination="{
        total: tableObject.total
      }"
      v-model:pageSize="tableObject.pageSize"
      v-model:currentPage="tableObject.currentPage"
    >
      <template #idCardUrl1="{ row }">
        <el-image
          :preview-teleported="true"
          style="width: 100px; height: 100px"
          :src="baseUrl + row.idCardUrl1"
          :zoom-rate="1.2"
          :preview-src-list="[baseUrl + row.idCardUrl1]"
          :max-scale="7"
          :min-scale="0.2"
          :initial-index="4"
          fit="cover"
        />
      </template>
      <template #applicantPhone="{ row }">
        {{Base64.decode(row.applicantPhone)}}
      </template>
      <template #idCardUrl2="{ row }">
        <el-image
          :preview-teleported="true"
          style="width: 100px; height: 100px"
          :src="baseUrl + row.idCardUrl2"
          :zoom-rate="1.2"
          :preview-src-list="[baseUrl + row.idCardUrl2]"
          :max-scale="7"
          :min-scale="0.2"
          :initial-index="4"
          fit="cover"
        />
      </template>
      <template #file="{ row }">
        <span class="text-#1890ff" @click="openResource(row.id)">显示材料</span>
      </template>
      <template #action="{ row }">
        <el-button
          link
          type="primary"
          @click="openAudit(row.id)"
          v-if="row.status == 1"
          v-hasPermi="['pro:detention-review-center:shenhe']"
        >
          <Icon icon="ep:pointer" />
          审核
        </el-button>
        <!-- <el-button
          link
          type="primary"
          @click="openPass(row.id)"
          v-if="row.status == 1"
          v-hasPermi="['pro:detention-review-center:shenhe']"
        >
          <Icon icon="ep:select" />
          完成
        </el-button> -->

        <!-- <el-button
          link
          type="primary"
          @click="
            openRedeploy(row.id, { oldUser: row.acceptUserName, oldUserId: row.acceptUserId })
          "
          v-hasPermi="['pro:detention-review-center:zhuan']"
        >
          <Icon icon="ep:switch" />
          转单/派单
        </el-button>
        <el-button
          link
          type="primary"
          @click="openHistory(row.id)"
          v-hasPermi="['pro:detention-review-center:zhuan']"
        >
          <Icon icon="ep:tickets" />
          转单/派单记录
        </el-button> -->
        <el-button
          link
          type="danger"
          v-hasPermi="['pro:detention-review-center:delete']"
          @click="handleDelete(row.id)"
        >
          <Icon icon="ep:delete" />
          删除
        </el-button>
      </template>
    </Table>
  </ContentWrap>

  <!-- 表单弹窗：添加/修改 -->
  <PetitionRequestRecordForm ref="formRef" @success="getList" />
  <CaseQueryResource ref="ResourceRef" type="jiYa" />
  <CaseQueryRecordForm ref="formRef" @success="getList" />
  <CaseQueryRecordAudit ref="auditRef" type="jiYa" @success="getList" />
  <CaseQueryRecordRedeploy ref="redeployRef" type="jiYa" @success="getList" />
  <CaseQueryRecordHistory ref="historyRef" type="jiYa" />
</template>
<script setup lang="ts" name="DetentionReviewCenter">
import { allSchemas } from './detentionReviewCenter.data'
import {Base64} from 'js-base64'
import * as RoleApi from '@/api/system/role'
import * as DetentionReviewCenterApi from '@/api/pro/detentionreviewcenter'
import DetentionReviewCenterForm from './DetentionReviewCenterForm.vue'
import CaseQueryResource from '../casequeryrecord/CaseQueryResource.vue'
import CaseQueryRecordForm from '../casequeryrecord/CaseQueryRecordForm.vue'
import CaseQueryRecordRedeploy from '../casequeryrecord/CaseQueryRecordRedeploy.vue'
import CaseQueryRecordHistory from '../casequeryrecord/CaseQueryRecordHistory.vue'
import CaseQueryRecordAudit from '../casequeryrecord/CaseQueryRecordAudit.vue'
const baseUrl = import.meta.env.VITE_BASE_URL
import { useUserStore } from '@/store/modules/user'
const userStore = useUserStore()
const acceptUserId = ref(undefined)
let getRole = userStore.roles.indexOf('jiYa') !== -1
// tableObject：表格的属性对象，可获得分页大小、条数等属性
// tableMethods：表格的操作对象，可进行获得分页、删除记录等操作
// 详细可见：https://doc.iocoder.cn/vue3/crud-schema/
const { tableObject, tableMethods } = useTable({
  getListApi: DetentionReviewCenterApi.getDetentionReviewCenterPage, // 分页接口
  delListApi: DetentionReviewCenterApi.deleteDetentionReviewCenter, // 删除接口
  defaultParams: { acceptUserId: acceptUserId.value }
})
// 获得表格的各种操作
const { getList, setSearchParams } = tableMethods

/** 添加/修改操作 */
const formRef = ref()
const ResourceRef = ref()
const auditRef = ref()
const redeployRef = ref()
const historyRef = ref()
const openForm = (type: string, id?: number) => {
  formRef.value.open(type, id)
}

/** 删除按钮操作 */
const handleDelete = (id: number) => {
  tableMethods.delList(id, false)
}
const openResource = (id: number) => {
  ResourceRef.value.open(id)
}
const openAudit = (id: number) => {
  auditRef.value.open(id)
}
const openRedeploy = (id: number, acceptUser) => {
  redeployRef.value.open(id, acceptUser)
}
const openHistory = (id) => {
  historyRef.value.open(id)
}
const openPass = (id) => {
  ElMessageBox.confirm('确认完成该案件吗？', '提示', {
    confirmButtonText: '确 认',
    cancelButtonText: '取 消'
  })
    .then(async () => {
      await DetentionReviewCenterApi.updateDetentionReviewCenter({ id: id, status: 2 })
      getList()
    })
    .catch(() => console.info('操作取消'))
}

/** 初始化 **/
onMounted(async () => {
  if (getRole) {
    let roleId = await RoleApi.getRolePage({ code: 'jiYa' })
    roleId.list.length > 0 && (acceptUserId.value = roleId.list[0].id)
   
  }
  setSearchParams({acceptUserId: acceptUserId.value})
})
</script>
